package com.adv.ems.filters;

import com.adv.ems.filters.dto.FilterParam;
import com.adv.ems.model.vo.ResultVO;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Data
public abstract class EnergyDataBaseFilter<K, T> {
    protected EnergyDataBaseFilter<K, T> next;
    protected int order;
    protected abstract String getFilterName();
    protected abstract double getOrder();
    protected abstract boolean isBefore();
    protected abstract String getType();
    protected abstract ResultVO<T> handle(FilterParam<K> param);
    protected ResultVO<T> filter(FilterParam<K> param) {
        log.info("filter----开始[name:{},order:{}]", getFilterName(), getOrder());
        ResultVO<T> handleRs = handle(param);
        log.info("filter----结束[name:{},success:{},content:{}, msg:{}]",getFilterName(), handleRs.isSuccess(), handleRs.getContent(), handleRs.getMsg());
        return !handleRs.isSuccess() || getNext() == null ? handleRs: getNext().filter(param);
    }
}
